package com.demo.crm.springboot3security.entity;

import java.time.LocalDateTime;
import java.util.List;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.RelationManyToOne;
import com.mybatisflex.annotation.RelationOneToMany;
import com.mybatisflex.annotation.Table;

import lombok.Data;

/**
 * 自定义表单实体
 */
@Data
@Table("custom_forms")
public class CustomForm {
    @Id(keyType = KeyType.Auto)
    private Long id;

    @Column("name")
    private String name; // 表单名称

    @Column("code")
    private String code; // 表单编码，唯一标识

    @Column("description")
    private String description; // 表单描述

    @Column("layout_config")
    private String layoutConfig; // 布局配置（JSON格式）

    @RelationManyToOne(selfField = "module_id", targetField = "id")
    private Module module; // 所属模块

    @RelationOneToMany(selfField = "id", targetField = "formId")
    private List<FormField> fields; // 表单字段

    @RelationOneToMany(selfField = "id", targetField = "sourceFormId")
    private List<FormRelation> sourceRelations; // 作为源表单的关联关系

    @RelationOneToMany(selfField = "id", targetField = "targetFormId")
    private List<FormRelation> targetRelations; // 作为目标表单的关联关系

    @Column("published")
    private boolean published; // 是否发布

    @Column("created_at")
    private LocalDateTime createdAt;

    @Column("updated_at")
    private LocalDateTime updatedAt;

    public void prePersist() {
        createdAt = LocalDateTime.now();
        updatedAt = LocalDateTime.now();
    }

    public void preUpdate() {
        updatedAt = LocalDateTime.now();
    }
}